const pageLoader = require('./node_modules/@lr17/loader/src/load/page.js')

const paths: string[] = ['pages/index', 'pages/asset']

pageLoader.load({
  component: {
    from: './node_modules/@dt/page/dist/components',
    paths
  },
  page: {
    from: './node_modules/@dt/page/dist/pages_com',
    paths: ['web', 'privacy']
  }
})

const moment = require('moment')
const childProcess = require('child_process')
const buildDate = `${moment(new Date()).format('YYYYMMDD')}`
const version = childProcess
  .execSync('git rev-parse --abbrev-ref HEAD')
  .toString()
  .replace(/\s+/, '')
  .split('-')
  .pop()
  .split('/')
  .pop()

import pathLoader from './node_modules/@lr17/loader/src/load/path.js'

import uni from '@dcloudio/vite-plugin-uni'
import { defineConfig } from 'vite'
const pathLoaderPlugin: any = pathLoader({ paths })
const { resolve } = require('path')

process.env.VITE_BUILD_DATE = buildDate
process.env.VITE_BUILD_VERSION = version

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [uni(), pathLoaderPlugin],
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@import "@/style/main.scss";`
      }
    }
  },
  resolve: {
    alias: {
      __biz: resolve('./node_modules/@dt/page/dist/biz')
    }
  }
})
